package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrapp.base.service.MOmsReportHolidayHandlingStrategyService;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsReportHolidayHandlingStrategyMapper;
import com.wicket.okrapp.dal.po.mbg.OmsReportHolidayHandlingStrategy;
import com.wicket.okrapp.base.service.dto.req.*;
//import com.wicket.okrapp.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;

import java.util.*;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsReportHolidayHandlingStrategyServiceImpl
  extends ServiceImpl<OmsReportHolidayHandlingStrategyMapper, OmsReportHolidayHandlingStrategy>
  implements MOmsReportHolidayHandlingStrategyService {

  @Autowired
  OmsReportHolidayHandlingStrategyMapper omsReportHolidayHandlingStrategyMapper;
/**
   * 3-4-06新增租户节假日设置[5307]
   * gen by moon at 11/29/2022, 11:03:59 AM
   */
 @Trace(operationName = "3-4-06新增租户节假日设置")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addTenantHolidaySet(OmsReportHolidayHandlingStrategy omsReportHolidayHandlingStrategy) {
     omsReportHolidayHandlingStrategy.setHolidayStrategyId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsReportHolidayHandlingStrategy.setIsArchive("FALSE");
omsReportHolidayHandlingStrategy.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsReportHolidayHandlingStrategy.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(omsReportHolidayHandlingStrategy!=null && omsReportHolidayHandlingStrategy.getSubjectLifeCycle()!=null &&  omsReportHolidayHandlingStrategy.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            omsReportHolidayHandlingStrategy.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
if(omsReportHolidayHandlingStrategy!=null && omsReportHolidayHandlingStrategy.getSubjectLifeCycle()!=null && omsReportHolidayHandlingStrategy.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsReportHolidayHandlingStrategy.setArchiveInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//ARCHIVE_CURRENT_INDUCTIONID
          }
omsReportHolidayHandlingStrategy.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsReportHolidayHandlingStrategy.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(omsReportHolidayHandlingStrategy!=null && omsReportHolidayHandlingStrategy.getSubjectLifeCycle()!=null && omsReportHolidayHandlingStrategy.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             omsReportHolidayHandlingStrategy.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
if(omsReportHolidayHandlingStrategy!=null && omsReportHolidayHandlingStrategy.getSubjectLifeCycle()!=null && omsReportHolidayHandlingStrategy.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsReportHolidayHandlingStrategy.setArchiveTime(CommonFunctionHelper.getCurrentTime());//HISTORICAL_ARCHIVING
          }
omsReportHolidayHandlingStrategy.setIsValid("FALSE");
omsReportHolidayHandlingStrategy.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsReportHolidayHandlingStrategy.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsReportHolidayHandlingStrategy)){
        return omsReportHolidayHandlingStrategy.getHolidayStrategyId();
     }else {
        return "-1";
     }
    
  }
/**
   * 3-4-06修改租户节假日设置[5308]
   * gen by moon at 11/29/2022, 11:03:59 AM
   */
 @Trace(operationName = "3-4-06修改租户节假日设置")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updateTenantHolidaySet(OmsReportHolidayHandlingStrategy omsReportHolidayHandlingStrategy) {
     omsReportHolidayHandlingStrategy.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsReportHolidayHandlingStrategy.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        return super.updateById(omsReportHolidayHandlingStrategy);
  }
/**
   * 3-4-06查询租户节假日设置详情[5309]
   * gen by moon at 11/29/2022, 11:04:00 AM
   */
 @Trace(operationName = "3-4-06查询租户节假日设置详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsReportHolidayHandlingStrategy  queryTenantHolidaySetDetail(QueryTenantHolidaySetDetailReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<OmsReportHolidayHandlingStrategy> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsReportHolidayHandlingStrategy> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsReportHolidayHandlingStrategy retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 3-4-06查询租户节假日设置列表[5310]
   * gen by moon at 11/29/2022, 11:04:01 AM
   */
 @Trace(operationName = "3-4-06查询租户节假日设置列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsReportHolidayHandlingStrategy>  queryTenantHolidaySetList(QueryTenantHolidaySetListReq reqDto) {
     
        try {
            QueryWrapper<OmsReportHolidayHandlingStrategy> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsReportHolidayHandlingStrategy.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsReportHolidayHandlingStrategy.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsReportHolidayHandlingStrategy.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsReportHolidayHandlingStrategy>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-4-06删除租户节假日设置[5313]
   * gen by moon at 11/29/2022, 7:39:57 PM
   */
 @Trace(operationName = "3-4-06删除租户节假日设置")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  deleteTenantHolidaySet(String holidayStrategyId ) {

      return super.removeById(holidayStrategyId);
  }

}

